﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ABC.Trips
{
    public struct LatandLong
	{
		public double Latitude;
        public double Longitude;
	}

    public class Distance
    {
        private double d_miles;
        public double D_miles
        {
            get { return d_miles; }
            set { d_miles = value; }
        }
        private double d_minutes;
        public double D_minutes
        {
            get { return d_minutes; }
            set { d_minutes = value; }
        }

        public static double getDistance(LatandLong start, LatandLong end)
        {
            double k;
            //ToDo: Needs testing. Compare with results from google API
            //source: http://stackoverflow.com/questions/3440104/how-to-calculate-the-distance-between-two-point-on-map
            double e = (Math.PI * start.Latitude / 180);
            double f = (Math.PI * start.Longitude / 180);
            double g = (Math.PI * end.Latitude / 180);
            double h = (Math.PI * end.Longitude / 180);
            double i = (Math.Cos(e) * Math.Cos(g) * Math.Cos(f) * Math.Cos(h) + Math.Cos(e) * Math.Sin(f) * Math.Cos(g) * Math.Sin(h) + Math.Sin(e) * Math.Sin(g));
            double j = (Math.Acos(i));
            k = (6371 * j); //6371 = radius of earth
            return k;
        }
    }
}
